﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Raven.Client;
using Topics.Radical.Windows.Presentation;
using Topics.Radical.Windows.Presentation.ComponentModel;

namespace Milestone.Presentation
{
	class PersonEditorViewModel : AbstractViewModel, ICanBeValidated
	{
		readonly IDocumentStore store;

		public PersonEditorViewModel( IDocumentStore store )
		{
			this.store = store;
		}

		public String FirstName
		{
			get { return this.GetPropertyValue( () => this.FirstName ); }
			set { this.SetPropertyValue( () => this.FirstName, value ); }
		}

		public String LastName
		{
			get { return this.GetPropertyValue( () => this.LastName ); }
			set { this.SetPropertyValue( () => this.LastName, value ); }
		}

		public void Save() 
		{
			var person = Model.Parties.Person.CreateNew( this.FirstName, this.LastName );
			using( var session = this.store.OpenSession() ) 
			{
				session.Store( person );
				session.SaveChanges();
			}
		}
	}
}
